package com.mdd.front.controller;
import com.mdd.common.entity.Company;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.entity.Feedback;
import com.mdd.common.entity.SystemHelp;
import com.mdd.common.util.StringUtils;
import com.mdd.front.LikeFrontThreadLocal;
import com.mdd.front.service.ISystemService;
import com.mdd.front.validate.common.PageValidate;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/api/system")
@Api(tags = "系统相关API")
public class SystemController {

	@Autowired
	private ISystemService systemService;
	
	
	
	@PostMapping("/submitFeedback")
	@ApiOperation(value = "提交意见反馈")
	public AjaxResult<Object> submitFeedback(@RequestBody Feedback feedback) {
		if(null == feedback) {
			return AjaxResult.failed("请输入意见/问题");
		}
		if(StringUtils.isEmpty(feedback.getContent())) {
			return AjaxResult.failed("请输入意见/问题");
		}
		if(StringUtils.isEmpty(feedback.getPhone())) {
			return AjaxResult.failed("请输入联系人电话");
		}
		if(StringUtils.isEmpty(feedback.getName())) {
			return AjaxResult.failed("请输入联系人姓名");
		}
		Integer userId = LikeFrontThreadLocal.getUserId();
		return systemService.submitFeedback(feedback,userId);
	}

	@PostMapping("/addCooperation")
	@ApiOperation(value = "添加商务合作")
	public AjaxResult<Object> addCooperation(@RequestBody Company company) {
		if(null == company) {
			return AjaxResult.failed("请输入公司名称");
		}
		if(StringUtils.isEmpty(company.getCompanyName())) {
			return AjaxResult.failed("请输入公司名称");
		}
		if(StringUtils.isEmpty(company.getRealName())) {
			return AjaxResult.failed("请输入姓名");
		}
		if(StringUtils.isEmpty(company.getMobile())) {
			return AjaxResult.failed("请输入手机号");
		}
		Integer userId = LikeFrontThreadLocal.getUserId();
		return systemService.addCooperation(company,userId);
	}

	@GetMapping("/aboutUs")
	@ApiOperation(value = "联系我们")
	public AjaxResult<Object> queryAboutUs() {
		return systemService.selectAboutUs();
	}
	
	@GetMapping("/helpCenter")
	@ApiOperation(value = "帮助中心")
	public AjaxResult<PageResult<SystemHelp>> helpCenter(@Validated PageValidate pageValidate) {
		PageResult<SystemHelp> helpCenter = systemService.helpCenter(pageValidate);
		return AjaxResult.success(helpCenter);
	}
	
	@GetMapping("/helpCenterBrowse")
	@ApiOperation(value = "帮助中心浏览")
	public AjaxResult<Object> helpCenterBrowse(Integer id) {
		return systemService.helpCenterBrowse(id);
	}
}
